Answer the following questions and complete the exercises in RMarkdown. Please embed all of your code and push your final work to your repository. Your final lab report should be organized, clean, and run free from errors. Remember, you must remove the # for the included code chunks to run. Be sure to add your name to the author header above. For any included plots, make sure they are clearly labeled. You are free to use any plot type that you feel best communicates the results of your analysis.
Make sure to use the formatting conventions of RMarkdown to make your report neat and clean!
library(tidyverse)
library(janitor)
library(here)
library(ggmap)
library(albersusa)
We will use two separate data sets for this homework.
The first data set represent sightings of grizzly bears (Ursos arctos) in Alaska.
The second data set is from Brandell, Ellen E (2021), Serological dataset and R code for: Patterns and processes of pathogen exposure in gray wolves across North America, Dryad, Dataset.
Load the grizzly data and evaluate its structure. As part of this step, produce a summary that provides the range of latitude and longitude so you can build an appropriate bounding box.
grizzly <- read_csv(here("lab12", "data", "bear-sightings.csv"))
##
## ── Column specification ────────────────────────────────────────────────────────
## cols(
## bear.id = col_double(),
## longitude = col_double(),
## latitude = col_double()
## )
glimpse(grizzly)
## Rows: 494
## Columns: 3
## $ bear.id <dbl> 7, 57, 69, 75, 104, 108, 115, 116, 125, 135, 137, 162, 185,…
## $ longitude <dbl> -148.9560, -152.6228, -144.9374, -152.8485, -143.2948, -149…
## $ latitude <dbl> 62.65822, 58.35064, 62.38227, 59.90122, 61.07311, 62.91605,…
grizzly %>%
select(latitude, longitude) %>%
summary()
## latitude longitude
## Min. :55.02 Min. :-166.2
## 1st Qu.:58.13 1st Qu.:-154.2
## Median :60.97 Median :-151.0
## Mean :61.41 Mean :-149.1
## 3rd Qu.:64.13 3rd Qu.:-145.6
## Max. :70.37 Max. :-131.3
lat <- c(55.02, 70.37)
long <- c(-166.2, -131.3)
bbox <- make_bbox(long, lat, f = 0.05)
stamen in a terrain style projection and display the map.map1 <- get_map(bbox, maptype = "terrain", source = "stamen")
## Map tiles by Stamen Design, under CC BY 3.0. Data by OpenStreetMap, under ODbL.
ggmap(map1)
ggmap(map1)+
geom_point(data = grizzly, aes(longitude, latitude))+
labs(title = "Grizzly Bear Observations in Australia", x = "Longitude", y = "Latitude") +
theme(plot.title = element_text(size = 14, face = "bold"),
axis.text = element_text(size = 10),
axis.title = element_text(size = 12))
wolves <- read_csv(here("lab12", "data", "wolves_data", "wolves_dataset.csv"))
##
## ── Column specification ────────────────────────────────────────────────────────
## cols(
## .default = col_double(),
## pop = col_character(),
## age.cat = col_character(),
## sex = col_character(),
## color = col_character()
## )
## ℹ Use `spec()` for the full column specifications.
wolves <- janitor::clean_names(wolves)
glimpse(wolves)
## Rows: 1,986
## Columns: 23
## $ pop <chr> "AK.PEN", "AK.PEN", "AK.PEN", "AK.PEN", "AK.PEN", …
## $ year <dbl> 2006, 2006, 2006, 2006, 2006, 2006, 2006, 2006, 20…
## $ age_cat <chr> "S", "S", "A", "S", "A", "A", "A", "P", "S", "P", …
## $ sex <chr> "F", "M", "F", "M", "M", "M", "F", "M", "F", "M", …
## $ color <chr> "G", "G", "G", "B", "B", "G", "G", "G", "G", "G", …
## $ lat <dbl> 57.03983, 57.03983, 57.03983, 57.03983, 57.03983, …
## $ long <dbl> -157.8427, -157.8427, -157.8427, -157.8427, -157.8…
## $ habitat <dbl> 254.08, 254.08, 254.08, 254.08, 254.08, 254.08, 25…
## $ human <dbl> 10.42, 10.42, 10.42, 10.42, 10.42, 10.42, 10.42, 1…
## $ pop_density <dbl> 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,…
## $ pack_size <dbl> 8.78, 8.78, 8.78, 8.78, 8.78, 8.78, 8.78, 8.78, 8.…
## $ standard_habitat <dbl> -1.6339, -1.6339, -1.6339, -1.6339, -1.6339, -1.63…
## $ standard_human <dbl> -0.9784, -0.9784, -0.9784, -0.9784, -0.9784, -0.97…
## $ standard_pop <dbl> -0.6827, -0.6827, -0.6827, -0.6827, -0.6827, -0.68…
## $ standard_packsize <dbl> 1.3157, 1.3157, 1.3157, 1.3157, 1.3157, 1.3157, 1.…
## $ standard_latitude <dbl> 0.7214, 0.7214, 0.7214, 0.7214, 0.7214, 0.7214, 0.…
## $ standard_longitude <dbl> -2.1441, -2.1441, -2.1441, -2.1441, -2.1441, -2.14…
## $ cav_binary <dbl> 1, 1, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,…
## $ cdv_binary <dbl> 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,…
## $ cpv_binary <dbl> 0, 0, 1, 1, 0, 1, 0, 0, 0, 0, 1, 0, 0, 1, 0, 0, 0,…
## $ chv_binary <dbl> 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 1, 1,…
## $ neo_binary <dbl> NA, NA, NA, 0, 0, NA, NA, 1, 0, 1, NA, 0, NA, NA, …
## $ toxo_binary <dbl> NA, NA, NA, 1, 0, NA, NA, 1, 0, 0, NA, 0, NA, NA, …
n_distinct(wolves$pop)
## [1] 17
wolves_lower_48 <- wolves %>%
filter(pop=="MI"| pop=="MT"| pop=="YNP"| pop=="GTNP"| pop=="SNF")
wolves_lower_48
## # A tibble: 988 x 23
## pop year age_cat sex color lat long habitat human pop_density
## <chr> <dbl> <chr> <chr> <chr> <dbl> <dbl> <dbl> <dbl> <dbl>
## 1 GTNP 2012 P M G 43.8 -111. 10375. 3924. 34.0
## 2 GTNP 2012 P F G 43.8 -111. 10375. 3924. 34.0
## 3 GTNP 2012 P F G 43.8 -111. 10375. 3924. 34.0
## 4 GTNP 2012 P M B 43.8 -111. 10375. 3924. 34.0
## 5 GTNP 2013 A F G 43.8 -111. 10375. 3924. 34.0
## 6 GTNP 2013 A M G 43.8 -111. 10375. 3924. 34.0
## 7 GTNP 2013 P M G 43.8 -111. 10375. 3924. 34.0
## 8 GTNP 2013 P M G 43.8 -111. 10375. 3924. 34.0
## 9 GTNP 2013 P M G 43.8 -111. 10375. 3924. 34.0
## 10 GTNP 2013 P F G 43.8 -111. 10375. 3924. 34.0
## # … with 978 more rows, and 13 more variables: pack_size <dbl>,
## # standard_habitat <dbl>, standard_human <dbl>, standard_pop <dbl>,
## # standard_packsize <dbl>, standard_latitude <dbl>, standard_longitude <dbl>,
## # cav_binary <dbl>, cdv_binary <dbl>, cpv_binary <dbl>, chv_binary <dbl>,
## # neo_binary <dbl>, toxo_binary <dbl>
albersusa package to make a base map of the lower 48 US states.us_comp <- usa_sf()
ggplot() +
geom_sf(data = us_comp, size = 0.125) +
theme_linedraw()+
labs(title = "USA State Boundaries", x="Longitude", y= "Latitude")+
theme(plot.title = element_text(size = 14, face = "bold"),
axis.text = element_text(size = 10),
axis.title = element_text(size = 12))
ggplot()+
geom_sf(data=us_comp, size=0.125)+
geom_point(data=wolves_lower_48, aes(long, lat))+
labs(title = "Wolf Populations in the USA", x="Longitude", y= "Latitude")+
theme(plot.title = element_text(size = 14, face = "bold"),
axis.text = element_text(size = 10),
axis.title = element_text(size = 12))
wolves %>%
group_by(pop) %>%
summarise(avg_pack_size = mean(pack_size)) %>%
arrange(desc(avg_pack_size))
## # A tibble: 17 x 2
## pop avg_pack_size
## <chr> <dbl>
## 1 BAN.JAS 9.56
## 2 ELLES 9.19
## 3 AK.PEN 8.78
## 4 YNP 8.25
## 5 GTNP 8.1
## 6 MI 7.12
## 7 DENALI 6.45
## 8 YUCH 6.37
## 9 INT.AK 6.24
## 10 BC 5.88
## 11 MT 5.62
## 12 SE.AK 5
## 13 SNF 4.81
## 14 ONT 4.37
## 15 MEXICAN 4.04
## 16 N.NWT 4
## 17 SS.NWT 3.55
ggplot()+
geom_sf(data=us_comp, size=0.125)+
geom_point(data=wolves_lower_48, aes(long, lat, size=pack_size))+
labs(title="Wolf Populations in the Lower 48 US States", x="Longitude", y="Latitude", size="Pack Size")+
theme(plot.title = element_text(size = 14, face = "bold"),
axis.text = element_text(size = 10),
axis.title = element_text(size = 12))
Please be sure that you check the keep md file in the knit preferences.